﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

/// <summary>
/// UI事件委托
/// </summary>
/// <param name="eventData"></param>
public delegate void PointerEventHandler(PointerEventData eventData);
/// <summary>
/// UI事件监听器
/// </summary>
public class UIEventListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler, IPointerUpHandler, IDragHandler, IEndDragHandler, IBeginDragHandler
{

    //声明事件
    /// <summary>
    /// 点击事件
    /// </summary>
    public event PointerEventHandler PointerClick;
    /// <summary>
    /// 按下事件
    /// </summary>
    public event PointerEventHandler PointerDown;
    /// <summary>
    /// 抬起事件
    /// </summary>
    public event PointerEventHandler PointerUp;
    /// <summary>
    /// 进入事件
    /// </summary>
    public event PointerEventHandler PointerEnter;
    /// <summary>
    /// 退出事件
    /// </summary>
    public event PointerEventHandler PointerExit;
    /// <summary>
    /// 开始拖动事件
    /// </summary>
    public event PointerEventHandler PointerBegainDrag;
    /// <summary>
    /// 拖动事件
    /// </summary>
    public event PointerEventHandler PointerDrag;
    /// <summary>
    /// 结束拖动事件
    /// </summary>
    public event PointerEventHandler PointerEndDrag;



    public void OnBeginDrag(PointerEventData eventData)
    {
        if (PointerBegainDrag != null)
        {
            PointerBegainDrag(eventData);
        }
    }

    /// <summary>
    /// 拖动时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnDrag(PointerEventData eventData)
    {
        if (PointerDrag != null)
        {
            PointerDrag(eventData);
        }
    }
    /// <summary>
    /// 结束拖动时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnEndDrag(PointerEventData eventData)
    {
        if (PointerEndDrag != null)
        {
            PointerEndDrag(eventData);
        }
    }
    /// <summary>
    /// 点击时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerClick(PointerEventData eventData)
    {
        if (PointerClick != null)
        {
            PointerClick(eventData);
        }
    }
    /// <summary>
    /// 按下时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerDown(PointerEventData eventData)
    {
        if (PointerDown != null)
        {
            PointerDown(eventData);
        }
    }
    /// <summary>
    /// 进入时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerEnter(PointerEventData eventData)
    {
        if (PointerEnter != null)
        {
            PointerEnter(eventData);
        }
    }
    /// <summary>
    /// 退出时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerExit(PointerEventData eventData)
    {
        if (PointerExit != null)
        {
            PointerExit(eventData);
        }
    }
    /// <summary>
    /// 抬起时触发
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerUp(PointerEventData eventData)
    {
        if (PointerUp != null)
        {
            PointerUp(eventData);
        }
    }
}
